﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace A2DFramework.HttpLoadBalancer.HttpProtocal
{
    /// <summary>
    /// HTTP回应报文
    /// </summary>
    public class HttpResponseEntity
    {
        public HttpResponseEntity()
        {
            this.HttpHeaders = new HttpHeadersCollection();
        }

        /// <summary>
        /// 回复头
        /// </summary>
        public ResponseStatusLine ResponseLine { get; set; }

        /// <summary>
        /// HTTP头列表
        /// </summary>
        public HttpHeadersCollection HttpHeaders { get; set; }

        /// <summary>
        /// 通用HTTP头
        /// </summary>
        public HttpHeadersCollection GeneralHeaders
        {
            get
            {
                if (this.HttpHeaders == null)
                    return null;

                var q = from headers in this.HttpHeaders
                        where headers.HeaderType == HttpHeaderType.General
                        select headers;
                HttpHeadersCollection collection=new HttpHeadersCollection();
                collection.AddRange(q.ToList());
                return collection;
            }
        }

        /// <summary>
        /// 回复HTTP头
        /// </summary>
        public HttpHeadersCollection ResponseHeaders
        {
            get
            {
                if (this.HttpHeaders == null)
                    return null;

                var q = from headers in this.HttpHeaders
                        where headers.HeaderType == HttpHeaderType.Response
                        select headers;
                HttpHeadersCollection collection=new HttpHeadersCollection();
                collection.AddRange(q.ToList());
                return collection;
            }
        }

        /// <summary>
        /// Entity HTTP头
        /// </summary>
        public HttpHeadersCollection EntityHeaders
        {
            get
            {
                if (this.HttpHeaders == null)
                    return null;

                var q = from headers in this.HttpHeaders
                        where headers.HeaderType == HttpHeaderType.Entity
                        select headers;
                HttpHeadersCollection collection=new HttpHeadersCollection();
                collection.AddRange(q.ToList());
                return collection;
            }
        }

        ///// <summary>
        ///// 消息体
        ///// </summary>
        //public string HttpBody { get; set; }
        public byte[] BodyBytes { get; set; }
    }

    /// <summary>
    /// 回复状态头
    /// </summary>
    public struct ResponseStatusLine
    {
        /// <summary>
        /// 状态码
        /// </summary>
        public int StatusCode { get; set; }

        /// <summary>
        /// 状态文本描述
        /// </summary>
        public string StatusDescription { get; set; }

        /// <summary>
        /// HTTP协议版本
        /// </summary>
        public HttpProtocalVersions Version { get; set; }
    }
}
